//
//  MyLiveViewController.m
//  斗鸡TV
//
//  Created by admin on 2017/2/10.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "MyLiveViewController.h"
#import "LFLiveKit.h"

#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
@interface MyLiveViewController ()<LFLiveSessionDelegate>

@property (nonatomic, strong) LFLiveSession *session;
@end

@implementation MyLiveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _session = [[LFLiveSession alloc]initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:[LFLiveVideoConfiguration defaultConfigurationForQuality:LFLiveVideoQuality_Medium2]];
    
    // 设置代理
    _session.delegate = self;
    _session.running = YES;
    _session.preView = self.view;
    // 开启后置摄像头,
    self.session.captureDevicePosition = AVCaptureDevicePositionBack;
    
    LFLiveStreamInfo *stream = [LFLiveStreamInfo new];
    // 如果是跟我blog教程搭建的本地服务器, 记得填写你电脑的IP地址
    stream.url = @"rtmp://71.0.0.57:1935/rtmplive/room";

    [self.session startLive:stream];
    
    UIButton * dismissBtn = [[UIButton alloc]initWithFrame:CGRectMake(WIDTH-50, 20, 40, 50)];
    [dismissBtn setTitle:@"关闭" forState:UIControlStateNormal];
    [dismissBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [dismissBtn addTarget:self action:@selector(dismissVc) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:dismissBtn];
}

-(void)dismissVc
{
    [self.session stopLive];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
